package com.liugh.service.impl;

import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.mail.MailUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.liugh.model.Mail;
import com.liugh.service.IMailService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class MailServiceImp implements IMailService {
    private final Log log = LogFactory.get();

    /**
     * 发送简单的文本文件
     * @param mail
     */
    public void sendSimpleMail(Mail mail) {
        MailUtil.sendText(mail.getTo(),mail.getSubject(),mail.getContent());
    }

    /**
     * 发送带附件的邮件
     * path为附件地址
     * @param mail
     */
    public void sendAttaMail(Mail mail) {
        MailUtil.sendText(mail.getTo(),mail.getSubject(),mail.getContent(),FileUtil.file(mail.getKvMap().get("path")));
    }

    /**
     * 群发邮件
     * @param list
     * @param mail
     */
    @Override
    public void sendMassMail(ArrayList<String> list, Mail mail) {
        MailUtil.send(list,mail.getSubject(),mail.getContent(),true);
    }


}
